package cn.yanjr.mall.mall_base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.yanjr.mall.mall_base.dao.SysDictDao;
import cn.yanjr.mall.mall_base.entity.SysDict;
import cn.yanjr.mall.mall_base.service.SysDictService;
import cn.yanjr.mall.mall_base.utils.DaoFactory;
import cn.yanjr.mall.mall_base.utils.MathUtils;

public class SysDictServiceImpl implements SysDictService {
	
	private SysDictDao sysDictDao = DaoFactory.sysDictDao;

	@Override
	public int save(SysDict dict) {
		return sysDictDao.save(dict);
	}

	@Override
	public int update(SysDict dict) {
		return sysDictDao.update(dict);
	}

	@Override
	public SysDict findOne(int id) {
		return sysDictDao.findOne(id);
	}

	@Override
	public int delete(int dictId) {
		return sysDictDao.delete(dictId);
	}

	@Override
	public Map<String, Object> findAllList(Map<String, Object> param) {
		int pageNo = Integer.parseInt(param.get("pageNo").toString());
		int pageSize = Integer.parseInt(param.get("pageSize").toString());
		
		Map<String, Object> map = new HashMap<String, Object>();
		int totals = sysDictDao.count();
		
		map.put("result", sysDictDao.findAllList());
		map.put("pageNo", pageNo);
		map.put("pageSize", pageSize);
		map.put("totalPages", MathUtils.ceil(totals, pageSize));
		map.put("totals", totals);
		
		return map;
	}
	
	@Override
	public List<String> findTypeList() {
		return sysDictDao.findTypeList();
	}

}
